﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using TSites.Xml;
namespace TSites.MasterCode
{
    public class TsMasterCode
    {
        private static TsMasterCode _instance;
        private static TsXmlEngine _xmlEngine;
        private static String _file;

        /// <summary>
        /// MasterCode resource
        /// </summary>
        private TsMasterCode() { }// Constructor

        public static TsMasterCode GetInstance(String file)
        {
            if (file == null)
                throw new Exception("The file can not be empty");

            if (_instance == null)
                _instance = new TsMasterCode();
            _instance.LoadFile(file);
            return _instance;
        }

        private void LoadFile(String file)
        {
            if (_xmlEngine == null)
            {
                _file = file;
                _xmlEngine = new TsXmlEngine(file);
            }
            else if (!file.Equals(_file))
            {
                _file = file;
                _xmlEngine = new TsXmlEngine(file);
            }
        }

        public String GetValue(String keyValue)
        {
            string a = _xmlEngine.GetContent("codeId", keyValue);
            return a;
        }
    }

}